const { createReadStream } = require("fs");

const readStream = createReadStream('./file.text', {
    start: 8,
    end:30
})

//readStream是一个event的一个实例
readStream.on('data', (data) => {
    readStream.pause();
    setTimeout(() => {
        console.log(data.toString());
    }, 20);
    console.log(data.toString());
})

//还可以监听到open事件
readStream.on('open', (fd) => {
    console.log(fd);
})

//还可以监听close事件
readStream.on('close', () => {
    console.log("文件关闭!!!!!");
})

//还可以监听end事件
readStream.on('end', () => {
    console.log("事件结束");
})